import axios from "axios";



const instance = axios.create({
  baseURL: '/api',
  timeout: 1000,
  headers: {'X-Custom-Header': 'foobar'}
});

instance.interceptors.request.use(function (config) {
  if (localStorage.getItem('token')) {
    config.headers.token = localStorage.getItem('token');
  }
  return config;
}, function (error) {
  return Promise.reject(error);
});
  
instance.interceptors.response.use(function (response) {

  if (response.headers.token) {
    localStorage.setItem("token", response.headers.token);
  }


  return response;
}, function (error) {
  return Promise.reject(error);
});

export default instance;